<script setup>
    import { ref, reactive} from 'vue';
    import { ElButton, ElInput, ElForm, ElFormItem,ElMessage } from 'element-plus';
    // import ElementPlus from 'element-plus';
    import 'element-plus/dist/index.css'
    import { Delete } from '@element-plus/icons-vue';
    import axios from 'axios';
    const button = reactive({
        value:false
    });
    const form = reactive({
        name:'',
        password:''
    });

    const onSubmit = async() =>{
        try{
            button.value = true;
            const response = await axios.get('http://api.cqhx.work:8080/api/teacher/login',{
                params:{
                    name:form.name,
                    password:form.password
                }
            });
            if(response.data.status === false){
                ElMessage.error('教师名或密码错误');
                button.value = false;
            }else if(response.data.status === true){
                ElMessage.success('登录成功');
                await new Promise(resolve => setTimeout(resolve, 1500))
                window.location.href = response.data.message;
            }
        }catch(error){
            console.error("请求失败",error);
        }
    }
    const onDelete = () =>{
        form.name = '';
        form.password = '';
    }
    // const 
</script>

<template>
    <div class="el-form">
        <el-form :model="form" label-width="auto" style="width: 300px;">
            <h2>账户登录</h2>
        <el-form-item label="教师名:" >
            <el-input v-model="form.name" type="text" placeholder="请输入教师名" class="el-input name-input" maxlength="10" clearable show-word-limit max-width="200"/>
        </el-form-item>
        <el-form-item label="密码:">
            <el-input v-model="form.password" type="password" placeholder="请输入密码" show-password class="el-input" maxlength="20" show-word-limit @keyup.enter="onSubmit" max-width="200"/>
        </el-form-item>
        <div>
            <el-button type="success" @click="onSubmit" round :disabled="button.value">登录</el-button>
            <el-button type="danger" @click="onDelete" :icon="Delete" circle/>
        </div>
        
    </el-form>
    </div>
</template>

<style>
/* 表单容器阴影 */
.el-form {
    max-width: 800px;
    width: 400px;
    margin: 10px auto;
    padding: 40px;
    font-family: '仿宋';
    background-color: rgba(250, 246, 246, 0.95);
    border-radius: 20px;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.1),    /* 主阴影 */
        0 1px 8px rgba(0, 0, 0, 0.07);      /* 细微阴影 */
}

/* 标题样式 */
.el-form h2 {
    text-align: center;
    font-size: 48px;  /* 增大标题字体 */
    margin-bottom: 40px;
    color: #2c3e50;
}




/* 背景样式 */
body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 2%, #c3cfe2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}

body::before,
    body::after{
        content: "";
        position: absolute;
        border-radius: 50%;
        z-index: 0;
    }

    body::before{
        width: 35vh;
        height: 35vh;
        background-color: #7875ac40;
        top: 3vh;
        left: -10vh;
    }

    body::after{
        width: 40vh;
        height: 40vh;
        background-color: #7875ac20;
        bottom: -0vh;
        right: -0vh;
    }

.el-input__inner::placeholder {
    font-family: '仿宋';
}

/* 按钮样式 */
.el-button {
    font-family: '仿宋';
    font-size: 20px;
    margin-right: 10px;
    padding: 10px 20px;
    border-radius: 5px;
}


</style>